﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using DAL;

namespace BLL
{
    public class ForRanking
    {
        public SqlDataReader Ranking()
        {
            string sql = string.Format(@"select Book.BookName,count(borrow.BookID) from Book
                            inner join BookClass on BookClass.ClassID = Book.ClassID
                            inner join BookType on Book.BookTypeID = BookType.BookTypeID
                            inner join Books on Book.ID = Books.ID
                            inner join Borrow on Books.BookID = Borrow.BookID
                            where books.BookID
                            in (select top 5 BookID from Borrow group by BookID order by count(BookID) desc)
                            group by Book.BookName
                            order by count(borrow.BookID) desc");

            SqlDataReader dr = DBHelper.ExecuteReader(sql);
            return dr;
        }
    }
}
